package com.qujia.markert.domain.vo;

import com.qujia.markert.domain.ReductionActivity;
import lombok.Getter;
import lombok.Setter;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.modelmapper.ModelMapper;

import java.util.StringJoiner;

/**
 * @date 2023/8/9
 */
@Getter
@Setter
public class ReductionActivityVO extends ReductionActivity {

    private String[] timeModes;

    private String[] memberLevels;

    private String[] paymentMethods;

    private String[] memberCategories;

    private String[] cardTypes;

    private String[] physicalCardTypes;


    public static ReductionActivity VOtoDO(ModelMapper mapper,ReductionActivityVO vo){
        if (vo==null) {
            return null;
        }
        ReductionActivity activity = mapper.map(vo, ReductionActivity.class);
        String[] modes = vo.getTimeModes();
        if (ArrayUtils.isNotEmpty(modes)) {
            StringJoiner joiner = new StringJoiner(",");
            for (String mode : modes) {
                joiner.add(mode);
            }
            activity.setTimeMode(joiner.toString());
        }else{
            activity.setTimeMode(null);
        }
        return activity;
    }

    public static ReductionActivityVO DOtoVO(ModelMapper mapper,ReductionActivity activity){
        if (activity == null) {
            return null;
        }
        ReductionActivityVO vo = mapper.map(activity, ReductionActivityVO.class);
        String timeMode = activity.getTimeMode();
        if(StringUtils.isNotBlank(timeMode)){
            vo.setTimeModes(timeMode.split(","));
        }else{
            vo.setTimeModes(null);
        }
        String memberLevel = activity.getMemberLevel();
        if (StringUtils.isNotBlank(memberLevel)) {
            vo.setMemberLevels(memberLevel.split(","));
        }else{
            vo.setMemberLevels(null);
        }
        String paymentMethod = activity.getPaymentMethod();
        if (StringUtils.isNotBlank(paymentMethod)) {
            vo.setPaymentMethods(paymentMethod.split(","));
        }else{
            vo.setPaymentMethods(null);
        }
        String memberCategory = activity.getMemberCategory();
        if (StringUtils.isNotBlank(memberCategory)) {
            vo.setMemberCategories(memberCategory.split(","));
        }else{
            vo.setMemberCategories(null);
        }

        String cardType = activity.getCardType();
        if (StringUtils.isNotBlank(cardType)) {
            vo.setCardTypes(cardType.split(","));
        }else{
            vo.setCardTypes(null);
        }

        String physicalCardType = activity.getPhysicalCardType();
        if (StringUtils.isNotBlank(physicalCardType)) {
            vo.setPhysicalCardTypes(physicalCardType.split(","));
        }else{
            vo.setPhysicalCardTypes(null);
        }
        return vo;
    }


}
